﻿using DoNet.Common.Helpers;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace DoNet.ApiHttpClient.Amap
{
    /// <summary>
    /// 高德地图API HttpClient 请求服务
    /// </summary>
    public static class AmapSetup
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="services"></param>
        public static void AddHttpClientAmap(this IServiceCollection services)
        {
            //循环API域名
            foreach (var api in AmapConst.ApiDomains)
            {
                services.AddHttpClient($"{AmapConst.HttpClientName}_{api.Key}", client =>
                {
                    client.BaseAddress = new Uri(DomainHelper.GetDomainName(api.Value, "", AmapConst.IsHttps));
                });
            }

            // 注册服务
            services.AddSingleton<AmapService>();
        }
    }
}
